package br.pucrs.lognplay.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "STATIC_VIEW_")
public class StaticView extends GenericEntity<String> {

	private static final long serialVersionUID = 1L;

	public enum Status {
		PENDING_INDEXING("Pending Indexing"), INDEXED("Indexed"), PENDING_REMOVAL("Pending Removal"), REMOVED("Removed");

		private final String label;

		Status(String label) {
			this.label = label;
		}

		public String getLabel() {
			return label;
		}
	}

	@Id
	@Column(name = "ID_")
	private String id;

	@Column(name = "NAME_")
	private String name;

	@Column(name = "DESCRIPTION_")
	private String description;

	@Column(name = "FROM_")
	@Temporal(TemporalType.TIMESTAMP)
	private Date from;

	@Column(name = "TO_")
	@Temporal(TemporalType.TIMESTAMP)
	private Date to;

	@Enumerated(EnumType.STRING)
	@Column(name = "STATUS_")
	private Status status;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "CLIENT_ID_", referencedColumnName = "ID_")
	private Client client;

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "STATIC_VIEW_LOG_SOURCE_", joinColumns = @JoinColumn(name = "STATIC_VIEW_ID_"), inverseJoinColumns = @JoinColumn(name = "LOG_SOURCE_ID_"))
	private List<LogSource> logSources = new ArrayList<>();

	public StaticView() {

	}

	public StaticView(UUID id) {
		this.id = id.toString();
	}

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getFrom() {
		return from;
	}

	public void setFrom(Date from) {
		this.from = from;
	}

	public Date getTo() {
		return to;
	}

	public void setTo(Date to) {
		this.to = to;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}

	public List<LogSource> getLogSources() {
		return logSources;
	}
}
